package com.hknc.btscale.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.hknc.btscale.bean.PlayBean;
import com.youth.banner.adapter.BannerAdapter;

import java.util.List;

/**
 * desc:
 * date:2021/9/16 16:34
 * author:sunguiyong
 */
public class ImageAdapter extends BannerAdapter<PlayBean.DataBean, ImageAdapter.BannerViewHolder> {
private Context mContext;
    public ImageAdapter(List<PlayBean.DataBean> datas, Context context) {
        super(datas);
        this.mContext=context;
    }

    @Override
    public BannerViewHolder onCreateHolder(ViewGroup viewGroup, int i) {
        ImageView imageView = new ImageView(viewGroup.getContext());
        //注意，必须设置为match_parent，这个是viewpager2强制要求的
        imageView.setLayoutParams(new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        return new BannerViewHolder(imageView);
    }

    @Override
    public void onBindView(BannerViewHolder bannerViewHolder, PlayBean.DataBean dataBean, int i, int i1) {
        Glide.with(mContext)
                .load(dataBean.getAdvertisingSlogan())
                .into(bannerViewHolder.imageView);
    }

    class BannerViewHolder extends RecyclerView.ViewHolder {
        ImageView imageView;

        public BannerViewHolder(@NonNull ImageView view) {
            super(view);
            this.imageView = view;
        }
    }
}
